﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ВУИ
{
    public partial class Lab : Form
    { 
        public int id;
        public Form1 Main;
        public Lab(int ID, Form1 MAIN)
        {
            InitializeComponent();
            id = ID;
            Main = MAIN;
            if (Main.lPatient[Main.itnPatietn(id)].Labis == null) Main.lPatient[Main.itnPatietn(id)].Labis = new lsd();
            if (Main.lPatient[Main.itnPatietn(id)].Labis.im == null) Main.lPatient[Main.itnPatietn(id)].Labis.im = new List<Imuno>();
            if (Main.lPatient[Main.itnPatietn(id)].Labis.oak == null) Main.lPatient[Main.itnPatietn(id)].Labis.oak = new List<OAK>();
            if (Main.lPatient[Main.itnPatietn(id)].Labis.pcr == null) Main.lPatient[Main.itnPatietn(id)].Labis.pcr = new List<PCR>();
            if (Main.lPatient[Main.itnPatietn(id)].Labis.scrin == null) Main.lPatient[Main.itnPatietn(id)].Labis.scrin = new List<Scrin>();
            if (Main.lPatient[Main.itnPatietn(id)].Labis.so == null) Main.lPatient[Main.itnPatietn(id)].Labis.so = new List<seroocc>();
            dataGridView1.DataSource = Main.lPatient[Main.itnPatietn(id)].Labis.oak;
            dataGridView2.DataSource = Main.lPatient[Main.itnPatietn(id)].Labis.im;
             
            refresh();
        }

        private void Lab_Load(object sender, EventArgs e)
        {

        }

        private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
        {

        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OAK e1 = new OAK();
            e1.Дата = DateTime.Now.Date;
            Main.lPatient[Main.itnPatietn(id)].Labis.oak.Add(e1);
            Main.ref_Lab();
            
        }

        private void удалитьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count == 1)
                Main.lPatient[Main.itnPatietn(id)].Labis.oak.RemoveAt(dataGridView1.Rows.IndexOf(dataGridView1.SelectedRows[0]));
            dataGridView1.DataSource = null;
            dataGridView1.DataSource = Main.lPatient[Main.itnPatietn(id)].Labis.oak;
        }

        private void новыйToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            Imuno e1 = new Imuno();
            e1.Дата = DateTime.Now.Date;
            Main.lPatient[Main.itnPatietn(id)].Labis.im.Add(e1);

            Main.ref_Lab();

        

        }

        private void удалитьToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (dataGridView2.SelectedRows.Count == 1)
                Main.lPatient[Main.itnPatietn(id)].Labis.im.RemoveAt(dataGridView2.Rows.IndexOf(dataGridView2.SelectedRows[0]));
            dataGridView2.DataSource = null;
            dataGridView2.DataSource = Main.lPatient[Main.itnPatietn(id)].Labis.im;
        }

        private void новыйToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Scrin s = new Scrin();
            s.data = new string[12];
            s.date = DateTime.Now;
            Main.lPatient[Main.itnPatietn(id)].Labis.scrin.Add(s);
            sero sc = new sero(id,Main.lPatient[Main.itnPatietn(id)].Labis.scrin.Count - 1, Main,this);
            sc.ShowDialog();

        }
        public void refresh()
        {
            TreeNode temp;
            treeView1.Nodes.Clear();
            foreach (Scrin s in Main.lPatient[Main.itnPatietn(id)].Labis.scrin)
            {
                temp = new TreeNode();
                temp.Text = s.date.ToShortDateString();
                temp.Tag = treeView1.Nodes.Count;
                treeView1.Nodes.Add(temp);

            }
            treeView2.Nodes.Clear();
            foreach (PCR s in Main.lPatient[Main.itnPatietn(id)].Labis.pcr)
            {
                temp = new TreeNode();
                temp.Text = s.Дата.ToShortDateString();
                temp.Tag = treeView2.Nodes.Count;
                treeView2.Nodes.Add(temp);

            }
            treeView3.Nodes.Clear();
            foreach (seroocc s in Main.lPatient[Main.itnPatietn(id)].Labis.so)
            {
                temp = new TreeNode();
                temp.Text = s.date.ToShortDateString();
                temp.Tag = treeView3.Nodes.Count;
                treeView3.Nodes.Add(temp);

            }
        }

        private void yjdsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PCR s = new PCR();
            s.Дата = DateTime.Now;
            Main.lPatient[Main.itnPatietn(id)].Labis.pcr.Add(s);
            Fpcr sc = new Fpcr(id, Main.lPatient[Main.itnPatietn(id)].Labis.pcr.Count - 1, Main, this);
            sc.ShowDialog();

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            fLabReport f = new fLabReport(Main, id);
            f.ShowDialog();
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Calc c = new Calc();
            c.Show();
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
           
        }

        private void treeView1_DoubleClick(object sender, EventArgs e)
        {
            
        }

        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (Convert.ToInt32(e.Node.Tag)>=0) 
            {
                sero sc = new sero(id, Convert.ToInt32(e.Node.Tag), Main, this);
                sc.ShowDialog();
            }

        }

        private void treeView2_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (Convert.ToInt32(e.Node.Tag) >= 0)
            {
                Fpcr sc = new Fpcr(id, Convert.ToInt32(e.Node.Tag), Main, this);
                sc.ShowDialog();
            }
        }

        private void удалитьToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(treeView1.SelectedNode.Tag) >= 0)
                Main.lPatient[Main.itnPatietn(id)].Labis.scrin.RemoveAt(Convert.ToInt32(treeView1.SelectedNode.Tag));
            refresh();
        }

        private void удалитьToolStripMenuItem3_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(treeView2.SelectedNode.Tag) >= 0)
                Main.lPatient[Main.itnPatietn(id)].Labis.pcr.RemoveAt(Convert.ToInt32(treeView2.SelectedNode.Tag));
            refresh();
        }

        private void dataGridView1_CellErrorTextNeeded(object sender, DataGridViewCellErrorTextNeededEventArgs e)
        {
           
        }

        private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            MessageBox.Show("Ошибка в вводимых данных. Проверете формат даты он должен быть дд.мм.гггг, а также остальные данные которые могут быть только числам");
            
        }

        private void dataGridView2_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {
            MessageBox.Show("Ошибка в вводимых данных. Проверете формат даты он должен быть дд.мм.гггг, а также остальные данные которые могут быть только числам");
        }

        private void новыйToolStripMenuItem2_Click(object sender, EventArgs e)
        {
            seroocc s = new seroocc();
            s.date = DateTime.Now;
            Main.lPatient[Main.itnPatietn(id)].Labis.so.Add(s);
            serooccs sc = new serooccs(id, Main.lPatient[Main.itnPatietn(id)].Labis.so.Count - 1, Main, this);
            sc.ShowDialog();
        }

        private void удалитьToolStripMenuItem4_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(treeView3.SelectedNode.Tag) >= 0)
                Main.lPatient[Main.itnPatietn(id)].Labis.so.RemoveAt(Convert.ToInt32(treeView3.SelectedNode.Tag));
            refresh();
        }

        private void treeView3_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (Convert.ToInt32(e.Node.Tag) >= 0)
            {
                serooccs sc = new serooccs(id, Convert.ToInt32(e.Node.Tag), Main, this);
                sc.ShowDialog();
            }

        }

    }
}
